<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var obj = {
      name: 'lisi',
      say: function () {
        console.log(this.name);

      }
    }

    var obj2 = {
      name: "kjakjsdba"
    }








    // if (!Function.prototype.mybind) {
    //   Function.prototype.mybind = function () {
    //     var self = this, // 保存原函数
    //       context = [].shift.call(arguments), // 保存需要绑定的this上下文
    //       args = [].slice.call(arguments); // 剩余的参数转为数组
    //     return function () { // 返回一个新函数
    //       self.apply(context, [].concat.call(args, [].slice.call(arguments)));
    //     }
    //   }
    // }




    // Function.prototype.mybind = function () {

    //   var arg = Array.prototype.slice.call(arguments)
    //   var shit = [].shift.call(arguments, 1)
    //   var content = this
    //   return function () {
    //     arg = arg.concat(Array.prototype.slice.call(arguments))
    //     return content.apply(shit, [].concat.call(arg, [].slice.call(arguments)))
    //   }
    // }


    Function.prototype.bindmy = function (obj, ...parmes) {


      let content = this

      let fn = function (...second) {
        let isnew = this instanceof fn
        let str = isnew ? this : obj
        return content.call(str, ...parmes, ...second)
      }

      fn.prototype = Object.create(content.prototype)
      return fn
    }

    let da = obj.say.bindmy(obj2)
    da()
  </script>
</body>

</html>